home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / IRIT.EL < prev    next >
Lisp/Scheme  |  1991-05-19  |  6KB  |  160 lines

  1. ; irit.el - Definitions of IRIT mode for emacs editor.
  2. ; Author:    Gershon Elber
  3. ;         Computer Science Dept.
  4. ;         University of Utah
  5. ; Date:    Tue May 14 1991
  6. ; Copyright (c) 1991, Gershon Elber
  7. ;
  8. ; This file defines an environment to run edit and execute IRIT programs.
  9. ; Such a program should have a '.irt' extension in order it to be in
  10. ; irit-mode major mode. Two new functions are provided to communicate
  11. ; between the editted file and the solid modeller:
  12. ; 1. send-line-to-irit - sends a single line to the solid modeller for
  13. ;    execution. A line is defined from current position to the next
  14. ;    semicolon ';'. If however several commands exists on the same line
  15. ;    they will all be send as one line.
  16. ;    Bounded to Meta-E by default.
  17. ; 2. send-region-to-irit - sends the region from the current mark (mark-marker)
  18. ;    to current position (point-marker) to the solid modeller. This function
  19. ;    is convenient for sending a large block of commands.
  20. ;    Bounded to Meta-R by default.
  21. ; Both functions checks for existance of a buffer named irit-solid-modeller
  22. ; and a process named "irit" hooked to it, and will restart a new process
  23. ; or buffer if none exists. The program to execute as process "irit" is
  24. ; defined by the irit-program constant below.
  25. ;
  26.  
  27. (defvar irit-program "irit"
  28.   "*The executable to run for irit-solid-modeller buffer.")
  29.  
  30. (defvar irit-echo-program nil
  31.   "*Control echo of executed commands to irit-solid-modeller buffer.")
  32.  
  33. (defvar irit-mode-map nil "")
  34. (if irit-mode-map
  35.     ()
  36.   (setq irit-mode-map (make-sparse-keymap))
  37.   (define-key irit-mode-map "\M-e" 'send-line-to-irit)
  38.   (define-key irit-mode-map "\M-r" 'send-region-to-irit))
  39.  
  40. ;;;
  41. ;;; Define the irit-mode
  42. ;;;
  43. (defun irit-mode ()
  44.   "Major mode for editing and executing IRIT files.
  45.  
  46. see send-line-to-irit and send-region-to-irit for more."
  47.   (interactive)
  48.   (use-local-map irit-mode-map)
  49.   (setq major-mode 'irit-mode)
  50.   (setq mode-name "Irit")
  51.   (run-hooks 'irit-mode-hook))
  52.  
  53. ;;;
  54. ;;; Define send-line-to-irit - send from current cursor position to next
  55. ;;; semicolin detected.
  56. ;;;
  57. (defun send-line-to-irit ()
  58.   "Sends one line of code from current buffer to the IRIT program.
  59.  
  60. Use to execute a line in the IRIT solid modeller. A line is anything
  61. that is terminated by a semicolon, but is at least one line of text so
  62. multiple commands per line (with several semicolons) are still
  63. considered a single line.
  64.  
  65. The IRIT solid modeller buffer name is irit-solid-modeller and the 
  66. process name is 'irit'. If none exists, a new one is created.
  67.  
  68. The name of the irit program program to execute is stored in irit-program
  69. and may be changed."
  70.   (interactive)
  71.   (if (equal major-mode 'irit-mode)
  72.     (progn
  73.       (make-irit-buffer)        ; In case we should start a new one.
  74.       (let ((start-mark (point-marker)))
  75.     (search-forward ";")
  76.     (let ((end-one-mark (point-marker)))
  77.       (goto-char start-mark)
  78.       (beginning-of-line)
  79.       (next-line 1)
  80.       (let* ((crnt-buffer (buffer-name))
  81.              (end-two-mark (point-marker))
  82.              (end-max-mark (max end-one-mark end-two-mark))
  83.          (string-copy (buffer-substring start-mark end-max-mark)))
  84.         (switch-to-buffer-other-window (get-buffer "irit-solid-modeller"))
  85.         (end-of-buffer)
  86.         (if irit-echo-program
  87.           (insert string-copy))
  88.         (set-marker (process-mark (get-process "irit")) (point-marker))
  89.         (if (not (pos-visible-in-window-p))
  90.           (recenter 3))
  91.         (switch-to-buffer-other-window (get-buffer crnt-buffer))
  92.         (process-send-region "irit" start-mark end-max-mark)
  93.         (goto-char end-max-mark)
  94.         (if (equal "\n" (buffer-substring (point-marker)
  95.                           (+ 1 (point-marker))))
  96.           (process-send-string "irit" "\n"))  
  97.         (if (> end-one-mark end-two-mark)
  98.           (forward-char 1))))))
  99.     (message "Should be invoked in irit-mode only.")))
  100.  
  101. ;;;
  102. ;;; Define send-region-to-irit - send from current cursor position to
  103. ;;; current marker.
  104. ;;;
  105. (defun send-region-to-irit ()
  106.   "Sends a region of code from current buffer to the IRIT program.
  107.  
  108. When this function is invoked on an IRIT file it send the region from current
  109. point to current mark to the irit solid modeller.
  110.  
  111. The IRIT solid modeller buffer name is irit-solid-modeller and the
  112. process name is 'irit'. If none exists, a new one is created.
  113.  
  114. The name of the irit program program to execute is stored in irit-program
  115. and may be changed."
  116.   (interactive)
  117.   (if (equal major-mode 'irit-mode)
  118.     (progn
  119.       (make-irit-buffer)     ; In case we should start a new one.
  120.       (copy-region-as-kill (mark-marker) (point-marker))
  121.       (let ((crnt-buffer (buffer-name)))
  122.     (switch-to-buffer-other-window (get-buffer "irit-solid-modeller"))
  123.     (end-of-buffer)
  124.     (if irit-echo-program
  125.       (yank))
  126.     (set-marker (process-mark (get-process "irit")) (point-marker))
  127.     (if (not (pos-visible-in-window-p))
  128.       (recenter 3))
  129.     (switch-to-buffer-other-window (get-buffer crnt-buffer))
  130.     (process-send-region "irit" (mark-marker) (point-marker))))
  131.     (message "Should be invoked in irit-mode only.")))
  132.  
  133. ;;;
  134. ;;; Switch to "irit-solid-modeller" buffer if exists. If not, creates one and
  135. ;;; execute the program defined by irit-program.
  136. ;;;
  137. (defun make-irit-buffer ()
  138.   "Switch to iris-solid-modeller buffer or create one if none exists"
  139.   (interactive)
  140.   (if (get-buffer "irit-solid-modeller")
  141.     (if (not (get-process "irit"))
  142.       (progn
  143.     (message "Starting IRIT solid modeller...")
  144.     (start-process "irit" "irit-solid-modeller" irit-program)
  145.     (process-send-string "irit" "\n")
  146.     (message "Done.")))
  147.     (progn
  148.       (message "Starting IRIT solid modeller...")
  149.       (start-process "irit" "irit-solid-modeller" irit-program)
  150.       (process-send-string "irit" "\n")
  151.       (message "Done."))))
  152.  
  153. ;;;
  154. ;;; Autoload irit-mode on any file with irt extension. 
  155. ;;;
  156. (setq auto-mode-alist (append '(("\\.irt$" . irit-mode))
  157.                   auto-mode-alist))
  158.